package com.wkx.controller;/**
 * @className: BookController
 * @description: TODO 类描述
 * @author: wkx
 * @date: 2022/4/7
 **/

import com.wkx.pojo.Type;
import com.wkx.service.AdminService;
import com.wkx.service.BookService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @ClassName : BookController  //类名

 * @Author : Lenovo //作者
 * @Date: 2022/4/7  21:06
 */
@Controller
@RequestMapping("book")
public class BookController {
    private Logger logger = LoggerFactory.getLogger(AdminController.class);
    @Reference(url = "dubbo://localhost:20882")
    private BookService bookService;
    @RequestMapping("getType")
    public String getType(Model model){
        logger.info("获取图书类型列表");
        List<Type> typeList = bookService.getTypeList();
        model.addAttribute("typeList",typeList);
        return "bookType";
    }

    @RequestMapping("addType")
    public String addType(Type type){
        logger.info("添加图书类型");
        bookService.addType(type);

        return "redirect:/book/getType";
    }

    @RequestMapping("updateType")
    public String updateType(Type type){
        logger.info("修改图书类型");
        bookService.updateType(type);

        return "redirect:/book/getType";
    }
    @RequestMapping("deleteType")
    public String deleteType(Integer tid){
        logger.info("删除图书类型");
        bookService.deleteType(tid);

        return "redirect:/book/getType";
    }

    @RequestMapping("toUpdateType")
    public String toUpdateType(Integer tid,Model model){
        logger.info("跳转到修改图书页面");
        Type type = bookService.getTypeById(tid);
        model.addAttribute("type",type);
        return "updateType";
    }
    @RequestMapping("toAddType")
    public String toAddType(){
        logger.info("跳转到添加图书页面");

        return "addType";
    }
}
